#! /bin/sh

module=scull
device=scull
mode=0664

# load module
modprobe ${module} $* || exit -1

# determine major no
major=$(awk "\$2 == \"${module}\" {print \$1}" /proc/devices)
[ -n ${major} ] || exit -2
echo "scull major: ${major}"

# rm devices
rm -f /dev/${device}[0-3]

mknod -m ${mode} /dev/${device}0 c ${major} 0
mknod -m ${mode} /dev/${device}1 c ${major} 1
mknod -m ${mode} /dev/${device}2 c ${major} 2
mknod -m ${mode} /dev/${device}3 c ${major} 3

# determine group name
group="staff"
$(grep -q '^staff:' /etc/group) || group="wheel"

chgrp ${group} /dev/${device}[0-3]
